// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently,
// but are changed infrequently

#pragma once

#ifndef _SECURE_ATL
#define _SECURE_ATL 1
#endif

#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
#endif

// Modify the following defines if you have to target a platform prior to the ones specified below.
// Refer to MSDN for the latest info on corresponding values for different platforms.
#ifndef WINVER                          // Specifies that the minimum required platform is Windows Vista.
#define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
#define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
#endif

#ifndef _WIN32_WINDOWS          // Specifies that the minimum required platform is Windows 98.
#define _WIN32_WINDOWS 0x0501 // Change this to the appropriate value to target Windows Me or later.
#endif

#ifndef _WIN32_IE                       // Specifies that the minimum required platform is Internet Explorer 7.0.
#define _WIN32_IE 0x0700        // Change this to the appropriate value to target other versions of IE.
#endif



#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS	// some CString constructors will be explicit

// turns off MFC's hiding of some common and often safely ignored warning messages
#define _AFX_ALL_WARNINGS

#include <afxwin.h>         // MFC core and standard components
#include <afxext.h>         // MFC extensions


#include <afxdisp.h>        // MFC Automation classes



#ifndef _AFX_NO_OLE_SUPPORT
#include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h>			// MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT

#include <afxcontrolbars.h>     // MFC support for ribbons and control bars

#include <imapi2.h>
#include <imapi2error.h>
#include <imapi2fs.h>
#include <imapi2fserror.h>
#include <shlwapi.h>        // for SHCreateStreamOnFileEx
#include <afx.h>
#include <afxctl.h>
#include <afxmt.h>
#include "resource.h"
#define SAFE_LOG(x, txt, end) {if (logger){char tmpbuf[30]; _strtime_s(tmpbuf, 30); *x << txt; if(end) *x << endl << tmpbuf << " ";}}
#define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; }

//http://support.microsoft.com/kb/KB932716   support site to get the IMAPI2 updates for XP etc.
#define EXPIREYEAR   2010
#define EXPIREMONTH  10
#define EXPIREDAY    31

#define PROGRAMNAME			"MagicBurner"
#define REGISTRYNAME		PROGRAMNAME
#define REGISTRYKEY			"SWN"
#define WEBSITE				"www.magicburner.com"
#define BINFILEWEBSITE		"www.magicburner.com"
#define VERFILENAME			"magicburner.ver"
#define PROGRAMEXENAME		"MagicBurner.exe"
#define PROGRAMDISPLAYNAME	"MagicBurner"
#define VERFILEFOLDER		"ftp"
#define BINFILEPATH			"ftp/bin"
#define PROGRAMWITHAUTHOR	"MagicBurner by Nic Wilson"


#define BLACK						RGB(0, 0, 0)
#define LCDBACKGROUND				RGB(179, 183, 139)
#define LCDOFFCOLOR					RGB(158, 164, 108)
#define BACKLITLCDBACKGROUND		RGB(99, 255, 206)
#define BACKLITLCDOFFCOLOR			RGB(97, 225, 181)
#define REDONCOLOR					RGB(255, 70, 10)
#define REDOFFCOLOR					RGB(80, 35, 0)
#define GREENONCOLOR				RGB(177, 255, 0)
#define GREENOFFCOLOR				RGB(0, 80, 0)
#define BLUEONCOLOR					RGB(6, 220, 255)
#define BLUEOFFCOLOR				RGB(0, 80, 100)
#define YELLOWONCOLOR				RGB(255, 242, 0)
#define YELLOWOFFCOLOR				RGB(80, 55, 0)
#define ORANGEONCOLOR				RGB(255, 180, 0)
#define ORANGEOFFCOLOR				RGB(80, 55, 0)
#define PURPLEONCOLOR				RGB(255, 80, 255)
#define PURPLEOFFCOLOR				RGB(80, 50, 80)
#define WHITEONCOLOR				RGB(255, 255, 255)
#define WHITEOFFCOLOR				RGB(80, 80, 80)

typedef struct _IMAPI_STATUS {
	// IDiscFormat2DataEventArgs Interface
	LONG elapsedTime;		// Elapsed time in seconds
	LONG remainingTime;		// Remaining time in seconds
	LONG totalTime;			// total estimated time in seconds
	// IWriteEngine2EventArgs Interface
	LONG startLba;			// the starting lba of the current operation
	LONG sectorCount;		// the total sectors to write in the current operation
	LONG lastReadLba;		// the last read lba address
	LONG lastWrittenLba;	// the last written lba address
	LONG totalSystemBuffer;	// total size of the system buffer
	LONG usedSystemBuffer;	// size of used system buffer
	LONG freeSystemBuffer;	// size of the free system buffer
	LONG currentTrack;
	BSTR currentFile;
	LONG copiedSectors;
	LONG totalSectors;
} IMAPI_STATUS, *PIMAPI_STATUS;

#define IMAPI_WRITE_ENGINE2_ACTION_WRITING_MEDIA 1234

#define MAX_PATH_UNICODE 32768
#define PROJECT_VERSION_SUPPORTED 1
#define CD_MEDIA		0
#define DVD_MEDIA		1
#define DL_DVD_MEDIA	2
#define BD_MEDIA		3
#define DL_BD_MEDIA		4
#define HDDVD_MEDIA		5
#define UNKNOWN_MEDIA	6

#define WM_BURN_STATUS_MESSAGE	WM_APP+300
#define WM_BURN_FINISHED		WM_APP+301
#define WM_ERASE_FINISHED		WM_APP+302
#define WM_UPDATEDATA			WM_APP+303
#define WM_IMAPI_UPDATE			WM_APP+304
#define WM_IMAPI_AUDIO_UPDATE	WM_APP+305
#define WM_IMAPI_RAW_UPDATE     WM_APP+309
#define WM_SYSTEMTRAY			WM_APP+306
#define WM_TRAY					WM_APP+307
#define WM_IMAPI_FS_UPDATE		WM_APP+308
#define IMAPI_FILESYSTEM_FILE_UPDATE 1

#define CLIENT_NAME		_T(PROGRAMNAME)

enum	{
			STARTUP_TIMER = 1,
			UPDATE_TIMER
};

enum	{
			WIZARD_BDROM = 0,
			WIZARD_DATA,
			WIZARD_DVDVIDEO, 
			WIZARD_ISOWRITE,
			WIZARD_MAKEISO,
			WIZARD_MUSICCD, 
			WIZARD_PHOTOCD,
			WIZARD_ERASE,
			WIZARD_ISOFROMDISC,
			WIZARD_MUSICCDDAO
};
enum	{
			PROGRAM_IDLE = 0,
			BURNING_DISC,
			ERASING_DISC,
			WRITING_ISO,
			MAKING_ISO,
			AUDIOCD_DISC,
			AUDIOCD_DAO,
			ISOFROM_DISC
};

enum	{
			UDF_AUTO = 0,
			UDF_102,
			UDF_105,
			UDF_200,
			UDF_201,
			UDF_250,
			UDF_260
		};

enum	{
			FS_AUTO = 0,
			FS_ISO9660,
			FS_ISO9660_JOLIET,
			FS_ISO9660_JOLIET_UDF,
			FS_ISO9660_UDF,
			FS_UDF,
			FS_AUDIOCD,
			FS_AUDIOCD_DAO
		};

enum	{
			WINDOWS95 = 0, 
			WINDOWS98ME, 
			WINDOWSNT4, 
			WINDOWS2000, 
			WINDOWSXP, 
			WINDOWSSERVER2003,
			WINDOWSLATER,
			WINDOWSVISTA,
			WINDOWSVISTALATER,
			WINDOWSBEYONDVISTA,
			WIN32_NTLATER,
			WINDOWS7
		};

#define FSi_AUDIOCD 106 
#define	FSi_AUDIOCD_DAO 107
#define RETURN_CANCEL_WRITE	0
#define RETURN_CONTINUE		1
#define ADDTOOL    m_pToolTip.AddTool(GetDlgItem
#define FREETOOL   m_pToolTip.DelTool(GetDlgItem

#define pMO        2
#define pMOE       3
#define pOWO       4
#define pASMO      5			
#define pCDROM     8
#define pCDR       9
#define pCDRW      10
#define pDVDROM    0x10
#define pDVDmR     0x11
#define pDVDRAM    0x12
#define pDVDRW     0x13
#define pDVDRWS    0x14
#define pDVDRDLR   0x15
#define pDVDRDL    0x16
#define pDVDDOWNLOAD 0x18
#define pDVDpRW    0x1A
#define pDVDpR     0x1B
#define pDVDpRWDL  0x2A
#define pDVDpR9    0x2B
#define pDDCDROM   0x20
#define pDDCDR     0x21
#define pDDCDRW    0x22
#define pHDBURNROM 0x80
#define pHDBURNR   0x81
#define pHDBURNRW  0x82
#define pBDROM     0x40
#define pBDR       0x41
#define pBDRW      0x43
#define pBDRE      0x42
#define pHDVDROM   0x50
#define pHDVDR     0x51
#define pHDVDRAM   0x52
#define pHDVDRW    0x53
#define pHDVDRDL   0x58
#define pHDVDRWDL  0x5A
	
#define mtCDROM     8
#define mtCDR       100
#define mtCDRW      101
#define mtDVDROM    0
#define mtDVDmR     2
#define mtDVDmRW    3
#define mtHDVDROM   4  
#define mtHDVDRAM   5
#define mtHDVDR     6
#define mtDVDmRDL   7
#define mtHDVDRW    0x53
#define mtHDVDRDL   0x58
#define mtHDVDRWDL  0x5A
#define mtDVDpRW    9
#define mtDVDpR     10
#define mtDVDRAM    11
#define mtDVDpRWDL	13
#define mtDVDpR9    14
#define mtBDROM		0x40
#define mtBDR		0x41
#define mtBDRE	    0x42
#define mtBDRW	    0x43

#define bDVDROM    0
#define bDVDRAM    1
#define bDVDmR     2
#define bDVDmRW    3
#define bDVDmRDL   7
#define bHDVDROM   4  
#define bHDVDRAM   5
#define bHDVDR     6
#define bHDVDRW    0x53
#define bHDVDRDL   0x58
#define bHDVDRWDL  0x5A
#define bDVDpRW    9
#define bDVDpR     10
#define bDVDpRWDL  13
#define bDVDpR9    14

#define HDVDROM   "HD DVD-ROM"
#define HDVDRW    "HD DVD-RW"
#define HDVDR     "HD DVD-R"
#define DVDRDL    "DVD-RDL"
#define DVDROM    "DVD-ROM"
#define DVDRAM    "DVD-RAM"
#define DVDR      "DVD-R"
#define DVDRW     "DVD-RW"
#define DVDPR     "DVD+R"
#define DVDPRW    "DVD+RW"
#define DVDPR9    "DVD+R DL"
#define DVDPRWDL  "DVD+RW DL"
#define BDROM     "BD-ROM"
#define BDR       "BD-R"
#define BDRE      "BD-RE"
static int decode(unsigned char const *, unsigned long);

#include "BurnCDDlg.h"
extern CBurnCDDlg* pThis;
__inline void FreeSysStringAndNull(BSTR &t)
{
	::SysFreeString(t);
	t = NULL;
	return;
}
#define SafeArrayDestroyDataAndNull(x) \
{                                      \
	if ((x) != NULL)                   \
	{                                  \
		SafeArrayDestroyData(x);       \
		(x) = NULL;                    \
	}                                  \
}
#define CoTaskMemFreeAndNull(x) \
	CoTaskMemFree(x);           \
	(x) = NULL;
#define ReleaseAndNull(x)       \
{                               \
	if ((x) != NULL)            \
	{                           \
		(x)->Release();         \
		(x) = NULL;             \
	}                           \
}
#define LocalFreeAndNull(x)     \
{                               \
	if ((x) != NULL)            \
	{                           \
		LocalFree(x);           \
		(x) = NULL;             \
	}                           \
}

#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif


